package View;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import Game.MouseAction;
import Game.Pieces;
import Game.Rule;
import Game.GameController;

import AI.AI;

public class MainPanel extends JFrame{
	public boolean firstTurn=true;
	public Pieces p;
	public BoardPanel bPanel;
	public GameController gc;
	public JTextField deepField;
	
	
	public MainPanel() {
		p = new Pieces();
		bPanel = new BoardPanel(p);
		gc=new GameController(this);
		bPanel.gc=gc;
		
		JPanel topPanel=new JPanel(new FlowLayout(FlowLayout.CENTER));
		
		final JButton turnButton=new JButton("First");
		turnButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(firstTurn==true) {
					turnButton.setText("Second");
				}else {
					turnButton.setText("First");
				}
				firstTurn=!firstTurn;
			}
			
		});
		deepField=new JTextField(5);
		deepField.setText("3");
		JLabel label=new JLabel("Search Deep");
		final JButton startButton=new JButton("Start");
		startButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				gc.start();
			}
			
		});
		
		final JButton undoButton=new JButton("Undo");
		undoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				gc.undo();
			}
		});
		topPanel.add(turnButton);
		topPanel.add(label);
		topPanel.add(deepField);
		topPanel.add(startButton);
		topPanel.add(undoButton);
		
		this.setLayout(new BorderLayout());
		this.add(topPanel,BorderLayout.NORTH);
		this.add(bPanel,BorderLayout.CENTER);
		this.setSize(new Dimension(bPanel.sizeX,bPanel.sizeY+50));
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
